home *** CD-ROM | disk | FTP | other *** search
- /* XGStdListBox.cpp
- *
- * Create a standard list box
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #include <string.h>
- #include <XApplication.h>
- #include <XStdControls.h>
- #include <XDataUtil.h>
- #include <XError.h>
- #include <XWindow.h>
- #include <XStdList.h>
-
- /************************************************************************/
- /* */
- /* Construction/Destruction */
- /* */
- /************************************************************************/
-
- /* XGStdListBox::XGStdListBox
- *
- * Create a standard list box
- */
-
- XGStdListBox::XGStdListBox(XGView *parent, XGArgStream &init) :
- XGStdList(parent,init,true)
- {
- Init(init.GetBoolean());
- }
-
- XGStdListBox::XGStdListBox(XGView *parent, XGSListInitRecord &init) :
- XGStdList(parent,init.v,true)
- {
- Init(init.msel);
- }
-
- /* XGStdListBox::~XGStdListBox
- *
- * Delete me
- */
-
- XGStdListBox::~XGStdListBox()
- {
- #if OPT_MACOS == 1
- if (fList) LDispose(fList);
- #endif
- }
-
- /************************************************************************/
- /* */
- /* Content modification */
- /* */
- /************************************************************************/
-
- /* XGStdListBox::Length
- *
- * Get the length of this thing
- */
-
- long XGStdListBox::Length() const
- {
- #if OPT_MACOS == 1
- return (**fList).dataBounds.bottom - (**fList).dataBounds.top;
- #endif
- }
-
- /* XGStdListBox::Insert
- *
- * Insert a new entry
- */
-
- void XGStdListBox::Insert(long pos, const char *c)
- {
- #if OPT_MACOS == 1
- Point p;
-
- InvalView();
- ::LSetDrawingMode(false,fList);
- ::LAddRow(1,pos,fList);
- p.h = 0;
- p.v = pos;
- ::LSetCell((Ptr)c,strlen(c),p,fList);
- ::LSetDrawingMode(true,fList);
- #endif
- }
-
- /* XGStdListBox::Delete
- *
- * Delete an entry
- */
-
- void XGStdListBox::Delete(long pos)
- {
- #if OPT_MACOS == 1
- InvalView();
- ::LSetDrawingMode(false,fList);
- ::LDelRow(1,pos,fList);
- ::LSetDrawingMode(true,fList);
- #endif
- }
-
- /* XGStdListBox::Get
- *
- * Get the contents of this row
- */
-
- void XGStdListBox::Get(long pos, char *c) const
- {
- #if OPT_MACOS == 1
- short len;
- Point p;
-
- p.h = 0;
- p.v = pos;
- ::LGetCell((Ptr)c,&len,p,fList);
- c[len] = 0;
- #endif
- }
-
- /* XGStdListBox::Set
- *
- * Set the contents of this thing
- */
-
- void XGStdListBox::Set(long pos, const char *c)
- {
- #if OPT_MACOS == 1
- Point p;
-
- InvalView();
- ::LSetDrawingMode(false,fList);
- p.h = 0;
- p.v = pos;
- ::LSetCell((Ptr)c,strlen(c),p,fList);
- ::LSetDrawingMode(true,fList);
- #endif
- }
-
- /************************************************************************/
- /* */
- /* Selection Routines */
- /* */
- /************************************************************************/
-
- /* XGStdListBox::GetSelect
- *
- * Get the first selected item.
- */
-
- long XGStdListBox::GetSelect(void) const
- {
- #if OPT_MACOS == 1
- Point pt;
-
- pt.h = 0;
- pt.v = 0;
- if (!::LGetSelect(true,&pt,fList)) return -1;
- return pt.v;
- #endif
- }
-
- /* XGStdListBox::IsSelect
- *
- * Is this selected?
- */
-
- bool XGStdListBox::IsSelect(long l) const
- {
- #if OPT_MACOS == 1
- Point pt;
-
- pt.h = 0;
- pt.v = l;
- if (!::LGetSelect(false,&pt,fList)) return false;
- return true;
- #endif
- }
-
-
- /* XGStdListBox::SetSelect
- *
- * Set the selected state. If this is a single select cell, this
- * will clear the other cells.
- */
-
- void XGStdListBox::SetSelect(long l, bool s)
- {
- #if OPT_MACOS == 1
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- Point pt;
- long i;
-
- if (fMultiSelect && s) {
- for (i = Length() - 1; i >= 0; i--) {
- pt.h = 0;
- pt.v = i;
- ::LSetSelect((l == i) ? true : false, pt, fList);
- }
- } else {
- pt.h = 0;
- pt.v = l;
- ::LSetSelect(s,pt,fList);
- }
- #endif
- }
-
- /* XGStdListBox::ClearSelect
- *
- * Clear the selected state.
- */
-
- void XGStdListBox::ClearSelect(void)
- {
- #if OPT_MACOS == 1
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- Point pt;
- long i;
-
- for (i = Length() - 1; i >= 0; i--) {
- pt.h = 0;
- pt.v = i;
- ::LSetSelect(false, pt, fList);
- }
- #endif
- }
-
- /************************************************************************/
- /* */
- /* Events */
- /* */
- /************************************************************************/
-
- /* XGStdListBox::DoDrawView
- *
- * Draw this thing
- */
-
- void XGStdListBox::DoDrawView(Rect r)
- {
- #if OPT_MACOS == 1
- Rect s;
- RgnHandle rgn;
-
- {
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- rgn = ::NewRgn();
- ViewToGlobal(&r);
- ::RectRgn(rgn,&r);
-
- ::LSetDrawingMode(true,fList);
- ::LUpdate(rgn,fList);
-
- ::DisposeRgn(rgn);
- }
-
- {
- XGDraw draw(this);
-
- s = GetContentRect();
- ::FrameRect(&s);
- }
- #endif
- }
-
- /* XGStdListBox::DoActivate
- *
- * Do activation/deactivation
- */
-
- void XGStdListBox::DoActivate(bool b)
- {
- #if OPT_MACOS == 1
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- ::LActivate(b,fList);
- #endif
- }
-
- /* XGStdListBox::DoMouseDown
- *
- * Handle mouse down event
- */
-
- bool XGStdListBox::DoMouseDown(Point pt, short)
- {
- #if OPT_MACOS == 1
- bool res;
-
- {
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- ViewToGlobal(&pt);
- res = ::LClick(pt,_GCurEvent.modifiers,fList);
- }
- if (res) {
- ReceiveDispatch(KEventListDblClk,GetViewID(),(void *)this);
- } else {
- ReceiveDispatch(KEventListSelect,GetViewID(),(void *)this);
- }
- #endif
-
- return false;
- }
-
- /* XGStdListBox::DoSizeView
- *
- * Do the size view
- */
-
- void XGStdListBox::DoSizeView()
- {
- #if OPT_MACOS == 1
- {
- Rect r;
- Point size;
- FontInfo finfo;
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- r = GetContentRect();
- ::InsetRect(&r,1,1);
- ::LSize(r.right-r.left-15,r.bottom-r.top,fList);
-
- size.h = r.right - r.left;
- GetFontInfo(&finfo);
- size.v = finfo.ascent + finfo.descent + finfo.leading;
- ::LCellSize(size,fList);
- }
- InvalView();
- #endif
- }
-
-
- /* XGStdListBox::DoMoveView
- *
- * Move to a new location
- */
-
- void XGStdListBox::DoMoveView()
- {
- #if OPT_MACOS == 1
- Rect r;
- XGDraw draw(this,false);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- r = GetContentRect();
- ViewToGlobal(&r);
- ::InsetRect(&r,1,1);
- (**fList).rView.top = r.top;
- (**fList).rView.left = r.left;
- #endif
- }
-
- /************************************************************************/
- /* */
- /* My initialization routine */
- /* */
- /************************************************************************/
-
- /* XGStdListBox::Init
- *
- * Initialization central
- */
-
- void XGStdListBox::Init(bool flag)
- {
- long l;
-
- l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
- fMultiSelect = flag;
-
-
- #if OPT_MACOS == 1
- XGDraw draw(this,false);
- Rect r;
- Rect d;
- Point size;
- FontInfo finfo;
-
- /*
- * Create the control at this location
- */
-
- fFont = GETHIWORD(l);
- fSize = GETLOWORD(l);
- ::TextFont(fFont);
- ::TextSize(fSize);
-
- r = GetContentRect();
- ViewToGlobal(&r);
- r.right -= 15;
- InsetRect(&r,1,1);
- size.h = r.right - r.left;
- GetFontInfo(&finfo);
- size.v = finfo.ascent + finfo.descent + finfo.leading;
-
- d.left = 0;
- d.right = 1;
- d.top = 0;
- d.bottom = 0;
- fList = ::LNew(&r, // Display rectangle
- &d, // initial data size
- size, // cell size in pixels
- 0, // Use default text proc
- GetWindow()->_GetGrafPtr(), // Window owner
- true, // Automatic redrawing
- false, // No grow box
- false, // No horizontal
- true); // Vertical box
-
- if (fList == NULL) {
- throw XPostError("Unable to create list box");
- }
-
- /*
- * Set list selector flags
- */
-
- if (!fMultiSelect) (**fList).selFlags |= lOnlyOne;
- #endif
- }
-